/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import mensch.Player;
import org.apache.log4j.Logger;

/**
 *
 * @author robert
 */
@ManagedBean(name="loginController")
@SessionScoped
public class Login {
    
    public Login(){
        
    }
    private final static Logger LOG = Logger.getLogger(Login.class.getName());
    
    @ManagedProperty(value = "#{player}")
    private Player loginPlayer;
    @ManagedProperty(value = "true")
    private boolean loginSuccess;
    @ManagedProperty(value = "#{registeredPlayers}")
    private RegisteredPlayers registeredPlayers;
    private String username;
    private String password;
    
    public String login(){
        LOG.info("Bin in der Login methode");
        LOG.info("Eingetragener Username: " + username);
        LOG.info("Status von loginSuccess: " + loginSuccess);
        loginPlayer = registeredPlayers.getRegisteredPlayer(username);
        
        if(loginPlayer != null && loginPlayer.getPassword().equals(password)){
            LOG.info("Player ungleich null Passwort angenommen, gehe zum Table");
            loginSuccess = true;
            return "table";
        }else{
            loginSuccess = false;
        }
        
        return "index";
    }

    public Player getLoginPlayer() {
        return loginPlayer;
    }

    public void setLoginPlayer(Player loginPlayer) {
        this.loginPlayer = loginPlayer;
    }

    public boolean isLoginSuccess() {
        return loginSuccess;
    }

    public void setLoginSuccess(boolean loginSuccess) {
        this.loginSuccess = loginSuccess;
    }

    public RegisteredPlayers getRegisteredPlayers() {
        return registeredPlayers;
    }

    public void setRegisteredPlayers(RegisteredPlayers registeredPlayers) {
        this.registeredPlayers = registeredPlayers;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        LOG.info("Setze Username auf: " + username);
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
